import Category from './CateEnum'
// 具体的笔记有哪些属性
class ItemData {
  id!: number; //用感叹号告诉编译器可以为空
  categoryId!: Category; //这里要用枚举类型enum 描述分类的各种情况1代表生活等等...
  title!: string;
  content!: string;
  createTime!: string;

  //-1以及''都为默认值
  constructor(id: number = -1, categoryId: Category = -1, title: string = '', content: string = '') {
    this.id = id;
    this.categoryId = categoryId;
    this.title = title;
    this.content = content;
    this.createTime = this.toSelfDateStr()
  }

  //自动创建时间 指定返回类型为string类型
  toSelfDateStr(): string {
    //将时间戳转换日期对象
    let date = new Date(Date.now());
    let monthString = ((date.getMonth() + 1) < 10) ? ('0' + date.getMonth()) : ('' + date.getMonth());
    //使用日期对象的getXXX方法依次获取年月日时分秒，拼接成想要的格式
    let dateString = date.getFullYear() + '-' + monthString + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes();
    return dateString;
  }
}

export default ItemData;